{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用concat()合并两个列表中的DataFrame："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd  \n",
    "  \n",
    "# 创建两个DataFrame  \n",
    "df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})  \n",
    "df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]})  \n",
    "df3 = pd.DataFrame({'A': [9, 10], 'B': [11, 12]})  \n",
    "  \n",
    "# 创建两个包含DataFrame的列表  \n",
    "list1 = [df1, df2]  \n",
    "list2 = [df3]  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[   A  B\n",
       " 0  1  3\n",
       " 1  2  4,\n",
       "    A  B\n",
       " 0  5  7\n",
       " 1  6  8]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    A   B\n",
      "0   1   3\n",
      "1   2   4\n",
      "0   5   7\n",
      "1   6   8\n",
      "0   9  11\n",
      "1  10  12\n"
     ]
    }
   ],
   "source": [
    "# 使用concat合并列表中的DataFrame  \n",
    "result = pd.concat(list1 + list2)  \n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用concat()合并两个DataFrame\n",
    "（虽然这不是列表合并，但经常用于合并DataFrame）："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    A   B\n",
      "0   1   3\n",
      "1   2   4\n",
      "2   5   7\n",
      "3   6   8\n",
      "4   9  11\n",
      "5  10  12\n"
     ]
    }
   ],
   "source": [
    "# 创建两个DataFrame  \n",
    "df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})  \n",
    "df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]})  \n",
    "df3 = pd.DataFrame({'A': [9, 10], 'B': [11, 12]}) \n",
    "\n",
    "# 使用concat函数合并DataFrame\n",
    "result = pd.concat([df1, df2, df3], axis=0, ignore_index=True)\n",
    "print(result)\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
